<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\controller;
use think\Loader;

class File extends CrmController
{
    /**
     * fileList
     */
    public function fileList()
    {
        $menuname = "File";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];     
        $this->assign("priv",$priv);

        // 模板输出
        return $this->fetch('fileList');
    }


    /**
     * 获取文件列表资料
     * @return [json] [公告数据]
     */
    public function fileDataList()
    {
        $page = $_REQUEST["page"];
        $limit = $_REQUEST["limit"];
        //需先判断传值是否为空
        $where = "(1 ";
        $where .= empty($_REQUEST["create_user"])?"":" AND create_user = '".$_REQUEST["create_user"]."'";
        $where .= empty($_REQUEST["start_createtime"])?"":" AND createtime > '".$_REQUEST["start_createtime"]."'";
        $where .= empty($_REQUEST["end_createtime"])?"":" AND createtime < '".$_REQUEST["end_createtime"]."'";
        $where .= " )";

        $arrData = Loader::model('File')->getFileData($where,$page,$limit);
        echo json_encode($arrData);
    }


    /**
     * 文件详情
     * @return [json] [文件详细信息]
     */
    public function fileDetails ()
    {
        $id = $_REQUEST["id"];
        $fileInfo = Loader::model('File')->getFileInfo($id);
        $this->assign('fileInfo',$fileInfo);
        return $this->fetch('fileDetails');
    }


    /**
     * 加载文件评论列表
     * @return [json] [文件评论列表]
     */
    public function fileCommentList ()
    {
        $id = $_REQUEST["id"];
        $fileCommentInfo = Loader::model('File')->getFileComment($id);
        echo json_encode($fileCommentInfo);
    }

}